package work.shyk.portal.baiduAPI;

import com.alibaba.fastjson.JSONObject;

/**
 * description: <br>
 * createTime: 2018/11/1411:19 <br>
 *
 * @author zzh
 */
public class TjApi {

    public static void test1() {
        try {
            JSONObject header = new JSONObject();
            header.put("username", "regedit0726");//用户名
            header.put("password", "MYbd102591243");//用户密码
            header.put("token", "9a84de531b2f0e4b1c8ea9057a345ff1");//申请到的token
            header.put("account_type", "1");

            String urlStr = "https://api.baidu.com/json/tongji/v1/ReportService/getSiteList";
            String charset = "utf-8";

            JSONObject params = new JSONObject();
            params.put("header", header);

            byte[] res = HttpsUtil.post(urlStr, params.toString(), charset);
            String s = new String(res);
            System.out.println(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void test2() {
        try {
            JSONObject header = new JSONObject();
            header.put("username", "regedit0726");//用户名
            header.put("password", "MYbd102591243");//用户密码
            header.put("token", "9a84de531b2f0e4b1c8ea9057a345ff1");//申请到的token
            header.put("account_type", "1");

//          String urlStr = "https://api.baidu.com/json/tongji/v1/ReportService/getSiteList";
            String urlStr = "https://api.baidu.com/json/tongji/v1/ReportService/getData";
            String charset = "utf-8";


            JSONObject body = new JSONObject();
            body.put("siteId","12730546");
            body.put("method","overview/getTimeTrendRpt");//需要获取的数据
            body.put("start_date","20181112");
            body.put("end_date","20181114");
            body.put("metrics","pv_count,visitor_count,ip_count");//指标,数据单位

            JSONObject params = new JSONObject();
            params.put("header", header);
            params.put("body", body);

            byte[] res = HttpsUtil.post(urlStr, params.toString(), charset);
            String s = new String(res);
            System.out.println(s);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        test1();
        System.out.println("----------------------------------------------------------------------------");
        test2();
    }

}